<?php
    class Statut {
        //Alias sur table : s
        public $id_statut;
        public $libelle;
        public $fin;
        public $valide;
		
        //Constructeur complet
        public function __construct($id_statut, $libelle, $fin, $valide) {
                $this->setId($id_statut);
                $this->setLibelle($libelle);
                $this->setFin($fin);
                $this->setValide($valide);
        }
		
        //Retourne le libellé du Statut
        //Paramètre : aucun
        //Retourne (String)
        public function __toString() {
            return $this->libelle;
        }
        
        //Retourne la couleur associé à cette commande
        //Paramètre : aucun
        //Retourne (String)
        public function getCouleur() {
            if($this->getId() == 1) {
                return "preparation";
            }
            else if($this->getId() == 2) {
                return "receptionne";
            }
            else if($this->getId() == 3) {
                return "envoyer";
            }
            else if($this->getId() == 4) {
                return "rembourse";
            }
        }
        
        //Récupère tout les statuts valide ou non
        //Paramètre : OPTIONNEL (Booléen)valide
        //Retourne (Statut)
        public static function getStatuts($valide = true) {
            $sql =  'SELECT
                        s.id_statut as sid_statut, s.libelle as slibelle, s.fin as sfin, s.valide as svalide
                    FROM statut s
                    WHERE
                        s.valide = '.intval($valide);
            $ps = Db::Execute($sql, true);
            $tabRetour = array();
            foreach($ps as $p) {
                $tabRetour[] = new Statut($p['sid_statut'], $p['slibelle'], $p['sfin'], $p['svalide']);
            }

            return $tabRetour;
        }
		
        //Crée un objet Statut grâce à son ID
        //Paramètre : (int)id
        //Retourne (Statut)
        public static function rechercheStatut($id) {
            $sql =  'SELECT
                        s.id_statut as sid_statut, s.libelle as slibelle, s.fin as sfin, s.valide as svalide
                    FROM statut s
                    WHERE
                        s.id_statut = '.intval($id);
            $ps = Db::Execute($sql, true);
            foreach($ps as $p) {
                return new Statut($p['sid_statut'], $p['slibelle'], $p['sfin'], $p['svalide']);
            }
            return null;
        }
		
        //GETTERS ET SETTERS
        public function getId() {return $this->id_statut;}
        public function getLibelle() {return $this->libelle;}
        public function getFin() {return $this->fin;}
        public function getValide() {return $this->valide;}

        public function setId($temp) {$this->id_statut = intval($temp);}
        public function setLibelle($temp) {$this->libelle = $temp;}
        public function setFin($temp) {$this->fin = intval($temp);}
        public function setValide($temp) {$this->valide = intval($temp);}
		
    }

?>